<%@page import="base.Base"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="sosr.serveur.IServeurRMI"%>
<%@page import="java.io.File"%>
<%@page import="sosr.bean.Medecin"%>
<%@page import="java.util.ArrayList"%>
<%@page import="sosr.bean.Patient"%>
<%@page import="bean.Valider"%>
<jsp:useBean id="pageConfig" scope="session" class="bean.Page"></jsp:useBean>
<jsp:useBean id="pageCGI" scope="session" class="bean.Page"></jsp:useBean>
<jsp:useBean id="logon" scope="session" class="bean.Connexion"></jsp:useBean>
<% 
int id = pageConfig.getAction_id();
System.out.println("#"+id);
%>

<%
IServeurRMI serv = logon.getSrvRMI();
serv.open();


Medecin p = serv.selectMedecin(id);

String identifiant = "";
String mdp = "";

if (p!= null) {
	 identifiant = p.getIdent();
}


request.setCharacterEncoding("UTF-8");
if (request.getParameter("submit") != null) {
	//boolean res = Valider.form(request, patient);
	boolean res = true;
	
	id = Integer.parseInt(request.getParameter("id"));
	identifiant = request.getParameter("identifiant");
	mdp = request.getParameter("mdp");
	
	if (res) {
		serv.open();
		boolean rp = false;
		if (id == -1) {
			p = new Medecin(0,identifiant,"?",identifiant,"",0,"","","","");
			rp = serv.addMedecin(p,mdp);
		}
		else {
			p.setIdent(identifiant);
			rp = serv.modUtilisateur(id,identifiant,mdp);
		}
		serv.close();
		
		if (rp) {
			pageCGI.setMessage("Notification","L'utilisateur "+p.getPrenom()+" "+p.getNom()+" a &eacute;t&eacute; modifi&eacute;e avec succ&egrave;s !");
			response.sendRedirect("../../acces.jsp");
		}
		
	}
}
else {

%>

<% if (id != -1) { %>
<h1>Modifier l'utilisateur #<%=id %></h1>
<% } else { %>
<h1>Ajouter un nouvel utilisateur</h1>
<% } %>

<form action="pages/moncompte/form_modacces.jsp" method="post" id="forminfo">
<input type="hidden" name="id" value="<%=id %>" />
<table cellpadding="0" cellspacing="0" class="main_form">
	<tr>
		<td>Identifiant</td>
		<td>
			<input type="text" name="identifiant" id="identifiant" value="<%=identifiant %>" class="field" />
		</td>
	</tr>
	<tr>
		<td>Mot de passe&nbsp;</td>
		<td>
			<input type="password" name="mdp" id="mdp" value="<%=mdp %>" class="field" />
		</td>
	</tr>
	<tr><td>&nbsp;</td><td></td></tr>
	<tr>
		<td colspan="2">
			<input type="submit" class="bouton" name="submit" value="Enregistrer" style="float: right" />
			<input type="reset" class="bouton" value="R&eacute;initialiser" style="float: right" />
		</td>
	</tr>
</table>
</form>

<% } %>
